using Brouteforce.NewManagers;
using Brouteforce.UserInterface.Abstracts;
using Brouteforce.UserInterface.Interfaces;
using Brouteforce.UserInterface.UIControls;
using Brouteforce.utilities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Brouteforce.Screens.PlayingScreen.Panels {
    public class CharacterStatusPanel : AbstractPanel {
        
        public CharacterStatusPanel()
            : base("CharacterStatusPanel") {

        }

        public override void Update(GameTime gameTime) {

        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) {
            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.LinearWrap,
                              DepthStencilState.Default, RasterizerState.CullNone);
            spriteBatch.Draw(UIControlManager.Instance.GreyStoneTexture, new Vector2(Bounds.X, Bounds.Y), Bounds, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
            spriteBatch.End();
            spriteBatch.Begin();
            Draws.DrawBorder(Bounds, new Color(91,91,91), 2);

            foreach (AbstractUIControl uiControl in Children)
            {
                uiControl.Draw(gameTime);
            }

        }

        //public override void Draw(GameTime gameTime) {

        //    Draws.DrawBorder(Bounds, Color.Yellow, 2);

        //    foreach (AbstractUIControl uiControl in Children) {
        //        uiControl.Draw(gameTime);
        //    }


        //}


        public override void AfterLayout() {

            
            var diffBetweenUIcontents = 15;
            //create Image for the character
            //toDo change the pic
            var img = UIControlManager.Instance.PlayerTexture;
            Image imageContent = new Image(img, "player Image",
                                           new Rectangle(
                                               (Bounds.Width - img.Width)/2,
                                               diffBetweenUIcontents, img.Width,
                                               img.Height));
            imageContent.setOffset(new Vector2(Bounds.X, Bounds.Y));
            AddUIControl(imageContent);
            var diffY = img.Height + diffBetweenUIcontents;


            //********************************** "Resources Status of the character"  ******************************************//

            //create "Human Status :" label
            var labelText = "Character Status";
            var diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            var midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X)/2;
            int textLabelHight = (int)diffBetweenLines.Y;
            Label label = new Label("Character Status label", labelText,
                                         new Rectangle(midPanelFotText, diffY, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            AddUIControl(label);


            //create "      Life :" label
            labelText = "Life :";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;

            label = new Label("Life label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 2 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);

            //create "      Light :" label
            labelText = "Light:";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;


            label = new Label("Light label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 3 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);

            //create "      Speed :" label
            labelText = "Speed:";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;


            label = new Label("Speed label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 4 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);

            //create "      Power :" label
            labelText = "Power:";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;


            label = new Label("Power label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 5 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);



            //******************************************* "Resources left for Turn" column **********************************//


            //create "Human Status :" label
            labelText = "Resources left \n for Turn";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;

            label = new Label("Resources left for Turn Status label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 6 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            AddUIControl(label);


            //create "      Life :" label
            labelText = "Life :";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;

            label = new Label("Life label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 9 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);

            //create "      Light :" label
            labelText = "Light:";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;


            label = new Label("Light label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 10 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);

            //create "      Speed :" label
            labelText = "Speed:";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;


            label = new Label("Speed label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 11 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);

            //create "      Power :" label
            labelText = "Power:";
            diffBetweenLines = Draws.CalculateWordSizeNormalFont(labelText);
            midPanelFotText = (int)(Bounds.Width - diffBetweenLines.X) / 2;


            label = new Label("Power label", labelText,
                                         new Rectangle(midPanelFotText, diffY + 12 * textLabelHight, (int)diffBetweenLines.X,
                                                       textLabelHight));
            label.setOffset(new Vector2(Bounds.X, Bounds.Y));
            label.SetLabelTextColor(Color.Black);
            AddUIControl(label);


        }
    }
}
